function fenjipaixu(json, lv = 4) {
    var fenjidizhili = '';
    console.log(json[0]);
    console.log(json[1]);
    function nextlv(lv) {
        lv = parseInt(lv);
        if (lv === 4) {
            return 6;
        } else {
            return lv + 1;
        }
    }
    console.log("lv" + lv);

    //有下级时增加
    $.each(json[0], function (k, v) {
        fenjidizhili += '<li><a href="#dizhichaxun' + nextlv(lv) + '">' + v + '</a></li>';//DOM编写
    })
    $('#dizhichaxun' + lv + ' article ul').html(fenjidizhili);//DOM增加

    $('.fenji article div').html("");
    //无下级显示信息
    if (json[1][0]) {
        var tabledetail = '<tr><td nowrap="nowrap">末级分光器名称</td><td nowrap="nowrap">安装位置及覆盖</td><td nowrap="nowrap">配比2</td><td nowrap="nowrap">同址分光器数</td><td nowrap="nowrap">地址属性</td><td nowrap="nowrap">备注1</td><td nowrap="nowrap">备注2</td></tr>';
        $.each(json[1], function (k, v) {
            console.log(v);
            var tabledetail2 = '<tr><td nowrap="nowrap">' + v['末级分光器名称'] + '</td><td nowrap="nowrap">' + v['安装位置及覆盖'] + '</td><td nowrap="nowrap">' + v['配比2'] + '</td><td nowrap="nowrap">' + v['同址分光器数'] + '</td><td nowrap="nowrap">' + v['地址属性'] + '</td><td nowrap="nowrap">' + v['备注1'] + '</td><td nowrap="nowrap">' + v['备注2'] + '</td></tr>';
            tabledetail += tabledetail2;
            console.log(tabledetail);
        });
        $('#dizhichaxun' + lv + ' article table').html(tabledetail);
}
}

/**
 * 分级索引
 * （点击部分）
 */

$(document).on("click", ".dizhifenji a", function () {
    $('.masklayer').show();
    $('.loadbox').show();
    var lvhash = location.hash;
    lv2 = lvhash.charAt(lvhash.length - 1);
    lv2 = parseInt(lv2);
    if (lv2 === 4) {
        lv2 = 5;
    }
    lv = lv2 + 1;
//    console.log("lvhash" + lv);
    var val = $(this).text();
//    console.log(val);//当前位置
    lvv = lv - 5;
    $('.fenji article>p span:nth-child(' + lvv + ')').text(val);//总地址
    for (lvvv = lvv + 1; lvvv < 10; lvvv++) {
        $('.fenji article>p span:nth-child(' + lvvv + ')').text("");//清空后边地址
    }
    var valarr = [];
    for (let i = 0; i < 5; i++) {
        valarr[i] = $('#vvv span:nth-child(' + (i + 1) + ')').text();
    }
    valstr = valarr.toString();
    console.log(valstr);
    new Ajax("gpon/fenji.php").keyvalue({"val": valstr}).getJson(function (json) {
        fenjipaixu(json, lv);
        $('.masklayer').hide();
        $('.loadbox').hide();
    });
    console.log($('#vvv').html());
});

/**
 * 分级索引
 * （自动加载部分）
 */

new Ajax("gpon/fenji.php").getJson(function (json) {

    fenjipaixu(json);

});



/**
 * 分级查询跳转
 * 
 * 
 * 
 */
$(document).on("click", ".fenjitable tr", function () {
    $('.masklayer').show();
    $('.loadbox').show();

    var neirong = $(this).find("td:first-child").text();
    var peibi = $(this).find("td:nth-child(3)").text();
    new Ajax("gpon/jump.php").keyvalue({"neirong": neirong, "peibi": peibi}).getJson(function (json) {
        $('.masklayer').hide();
        $('.loadbox').hide();
        console.log(json);
        var table = '<tr><td nowrap="nowrap">端子</td><td nowrap="nowrap">设备名称</td><td nowrap="nowrap">sn码</td><td nowrap="nowrap">电话号码</td><td nowrap="nowrap">宽带号码</td></tr>';
        if (json[0]) {
            $.each(json, function (k, v) {
                table += '<tr><td nowrap="nowrap" class="duanzi">' + v['端子'] + '</td><td nowrap="nowrap">' + v['设备名称'] + '</td><td nowrap="nowrap">' + v['sn码'] + '</td><td nowrap="nowrap">' + v['电话号码'] + '</td><td nowrap="nowrap">' + v['宽带号码'] + '</td></tr>';
            });
            console.log(table);
            $('#jumptb').html(table);
            $('#fenjijump header h1').text(neirong);
            location.hash = '#fenjijump';
        } else {
            remind1("没有设备", "确定");//提示信息

        }
    })
})

//分光器查询跳转
$(document).on("click", ".searchjump tr", function () {
    $('.masklayer').show();
    $('.loadbox').show();
    neirong = $(this).find('td:first-child').text();
    var peibi = $(this).find('td:nth-child(2)').text();
    new Ajax("gpon/jump.php").keyvalue({"neirong": neirong, "peibi": peibi}).getJson(function (json) {
        $('.masklayer').hide();
        $('.loadbox').hide();
        console.log(json);
        var table = '<tr><td nowrap="nowrap">端子</td><td nowrap="nowrap">设备名称</td><td nowrap="nowrap">sn码</td><td nowrap="nowrap">电话号码</td><td nowrap="nowrap">宽带号码</td></tr>';
        if (json[0]) {
            $.each(json, function (k, v) {
                table += '<tr><td nowrap="nowrap" class="duanzi">' + v['端子'] + '</td><td nowrap="nowrap">' + v['设备名称'] + '</td><td nowrap="nowrap">' + v['sn码'] + '</td><td nowrap="nowrap">' + v['电话号码'] + '</td><td nowrap="nowrap">' + v['宽带号码'] + '</td></tr>';
            });
            $('#jumptb').html(table);
            $('#fenjijump header h1').text(neirong);
            location.hash = '#fenjijump';
        } else {
            remind1("没有设备", "确定");//提示信息

        }
    });
})


/**
 * 分级详情页跳转
 * 
 */
$(document).on("click", ".fenjijump table tr", function () {
    $('.masklayer').show();
    $('.loadbox').show();
    var idx = $(this).index();
    if (idx !== 0) {    //除去表头
        var duanzi = $(this).find('.duanzi').text();
        console.log(duanzi);    //取得端子数

        var neirong = $('#fenjijump header>h1').text();
        console.log(neirong);
        new Ajax("gpon/jumpdetail.php").keyvalue({"neirong": neirong, "duanzi": duanzi}).getJson(function (json) {
            $('.masklayer').hide();
            $('.loadbox').hide();
            console.log(json);
            var tabledetail = '';
            $.each(json, function (k, v) {
                tabledetail += '<tr><td nowrap="nowrap">' + k + '</td><td nowrap="nowrap">' + v + '</td></tr>';
            });
            $('#jumpdetail').html(tabledetail);
            $('#fenjijumpdetail header h1').text(neirong + ' ' + duanzi + '端子');
            location.hash = '#fenjijumpdetail';
        });
    }
});

/**
 * hash改变重置页面
 * 
 */
$(window).on("hashchange", function () {
    switch (location.hash) {
        case '#gudingdianhuachaxun':
            $('#telinput').val("");
            $('#gudingdianhuadetail').html("");
        case '#kuandaichaxun':
            $('#kuandaiinput').val("");
            $('#kuandaidetail').html("");
    }
    //返回左边
//    var locahash=location.hash;
//    var offleft=$(locahash+" section").offset();
////    var offleft=document.getElementsByTagName("article").offsetLeft;
//    console.log(offleft);
});




//清空按钮
$('.inputdiv button:nth-child(3)').click(function () {
    $(this).prev().prev().val("");
    $(this).parent().next().html("");
});

/**
 * 固定电话查询
 * 
 */
$('#gudingdianhua button:nth-child(2)').click(function () {
    var tel = $('#telinput').val();
    if (tel.length === 7) {
        new Ajax("gpon/dianhuachaxun.php").keyvalue({"tel": tel}).getJson(function (json) {
            var n = true;
            var tabledetail = '';
            $.each(json, function (k, v) {
                if (k === "设备名称") {
                    if (!v) {
                        n = false;
                        return;
                    }
                }
                tabledetail += '<tr><td nowrap="nowrap">' + k + '</td><td nowrap="nowrap">' + v + '</td></tr>';
            });
            if (n) {
                $('#gudingdianhuadetail').html(tabledetail);
            } else {
                $('#gudingdianhuadetail').html("");
                remind1("电话号码不存在", "确定");
            }
        })
    } else {
        remind1("请输入7位固定电话", "确定");
    }
});

/**
 *   宽带号码查询
 *  
 */
$('#kuandai button:nth-child(2)').click(function () {
    var kuandai = $('#kuandaiinput').val();
    new Ajax("gpon/kuandaichaxun.php").keyvalue({"kuandaizhanghao": kuandai}).getJson(function (json) {
        var n = true;
        var tabledetail = '';
        $.each(json, function (k, v) {
            if (k === "设备名称") {
                if (!v) {
                    n = false;
                    return;
                }
            }
            tabledetail += '<tr><td nowrap="nowrap">' + k + '</td><td nowrap="nowrap">' + v + '</td></tr>';
        });
        if (n) {
            $('#kuandaidetail').html(tabledetail);
        } else {
            $('#kuandaidetail').html("");
            remind1("宽带号码不存在", "确定");
        }
    })
});


/**
 *   sn码查询
 *  
 */
$('#sncode button:nth-child(2)').click(function () {
    var sncode = $('#sninput').val();
    sncode = sncode.toUpperCase();
    new Ajax("gpon/sncode.php").keyvalue({"sn_code": sncode}).getJson(function (json) {
        var n = true;
        var tabledetail = '';
        $.each(json, function (k, v) {
            if (k === "设备名称") {
                if (!v) {
                    n = false;
                    return;
                }
            }
            tabledetail += '<tr><td nowrap="nowrap">' + k + '</td><td nowrap="nowrap">' + v + '</td></tr>';
        });
        if (n) {
            $('#sndetail').html(tabledetail);
        } else {
            $('#sndetail').html("");
            remind1("sn码不存在", "确定");
        }
    })
});

/**
 * 分光器查询
 */
$('#fenguanginput').bind("input propertychange", function () {
    var val = $(this).val();
    console.log(val);
    if (val == '' || val == null) {
        $('#fenguangdetail').html("");
    } else {
        new Ajax("gpon/fenguangchaxun.php").keyvalue({"val": val}).getJson(function (json) {
            console.log(json);
            var tabledetail = '<tr><td nowrap="nowrap">末级分光器名称</td><td nowrap="nowrap">配比2</td></tr>';
            $.each(json, function (k, v) {
                var tabledetail2 = '<tr>';
                $.each(v, function (key, val) {
                    tabledetail2 += '<td nowrap="nowrap">' + val + '</td>';
                });
                tabledetail2 += '</tr>';
                tabledetail += tabledetail2;
            });
            $('#fenguangdetail').html(tabledetail);
        });
    }
});


/**
 * 模糊查询
 */
$('#mohuinput').bind("input propertychange", function () {
    var val = $(this).val();
    console.log(val);
    if (val == '' || val == null) {
        $('#mohudetail').html("");
    } else {
        new Ajax("gpon/mohudizhichaxun.php").keyvalue({"val": val}).getJson(function (json) {
            console.log(json);
            var tabledetail = '';
            $.each(json, function (k, v) {
                tabledetail += '<tr><td nowrap="nowrap">' + v + '</td></tr>';
            });
            $('#mohudetail').html(tabledetail);
        });
    }
});
//模糊查询2级
$(document).on("click", "#mohudetail tr", function () {
    var place = $(this).find("td").text();
    console.log(place);
    new Ajax("gpon/mohudizhichaxun2.php").keyvalue({"place": place}).getJson(function (json) {
        console.log(json);
        var tabledetail = '<tr><td nowrap="nowrap">末级分光器名称</td><td nowrap="nowrap">配比2</td><td nowrap="nowrap">同址分光器数</td><td nowrap="nowrap">地址属性</td><td nowrap="nowrap">备注1</td><td nowrap="nowrap">备注2</td></tr>';
        $.each(json, function (k, v) {
            var tabledetail2 = '<tr>';
            $.each(v, function (key, val) {
                tabledetail2 += '<td nowrap="nowrap">' + val + '</td>';
            })
            tabledetail2 += '</tr>';
            tabledetail += tabledetail2;
        });
        $('#mohu2detail').html(tabledetail);
        $('#mohuchaxun2 header h1').text(place);
        location.hash = "#mohuchaxun2";
    });
});
//模糊查询3级
$(document).on("click", "#mohu2detail tr", function () {
    $('.masklayer').show();
    $('.loadbox').show();
    var neirong = $(this).find('td:first-child').text();
    var peibi = $(this).find('td:nth-child(2)').text()
    new Ajax("gpon/jump.php").keyvalue({"neirong": neirong, "peibi": peibi}).getJson(function (json) {
        $('.masklayer').hide();
        $('.loadbox').hide();
        console.log(json);
        var table = '<tr><td nowrap="nowrap">端子</td><td nowrap="nowrap">设备名称</td><td nowrap="nowrap">sn码</td><td nowrap="nowrap">电话号码</td><td nowrap="nowrap">宽带号码</td></tr>';
        if (json[0]) {
            $.each(json, function (k, v) {
                table += '<tr><td nowrap="nowrap" class="duanzi">' + v['端子'] + '</td><td nowrap="nowrap">' + v['设备名称'] + '</td><td nowrap="nowrap">' + v['sn码'] + '</td><td nowrap="nowrap">' + v['电话号码'] + '</td><td nowrap="nowrap">' + v['宽带号码'] + '</td></tr>';
            });
            $('#jumptb').html(table);
            $('#fenjijump header h1').text(neirong);
            location.hash = '#fenjijump';
        } else {
            remind1("没有设备", "确定");//提示信息
        }
    });
});
